package com.lwh.springboot.service.impl;
import com.lwh.springboot.service.IRentService;
import com.lwh.springboot.mapper.RentMapper;
import com.lwh.springboot.pojo.entity.Rent;
import com.lwh.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RentServiceImpl implements IRentService {
    @Autowired
    private RentMapper rentMapper;

    @Override
    public void deleteById(Integer id) {
        rentMapper.deleteById(id);
    }

    @Override
    public void add(Rent rent) {
        rentMapper.add(rent);
    }

    public void deleteAll(Integer[] ids) {
        rentMapper.deleteAll(ids);
    }

    public Rent selectById(Integer id) {
        return rentMapper.selectById(id);
    }

    @Override
    public void update(Rent rent) {
        rentMapper.update(rent);
    }

    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<Rent> list = rentMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = rentMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);
        return new PageInfo<Rent>(list, totalPage, pageNo, pageSize);
    }
}
